package android.githo;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }


    private void setBtnDialog(){
        ProgressDialog progressDialog = init();
        //  progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        /*
        STYLE_SPINNER 环型  ；STYLE_HORIZONTAL  长型；
         */
        progressDialog.show();//先调show在执行下一步
        progressDialog.setProgress(50);
    }
    private void setBtnDialog3(){
        final ProgressDialog progressDialog = init();
        //设置进度不确定  true表示不确定；false表示确定
        progressDialog.setIndeterminate(true);

        progressDialog.show();
        new Thread(new Runnable() {
            @Override
            public void run() {
                int progerss = 0;

                while (progerss <101){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    progressDialog.setIndeterminate(false);
                    //第一进度条
                    progressDialog.incrementProgressBy(3);
                    //第二进度条
                    progressDialog.incrementSecondaryProgressBy(6);
                    progerss++;
                    int psds =  progressDialog.getProgress();
                    if (psds == 100){
                        progressDialog.dismiss();
                    }
                }
            }
        }).start();
    }


    private void setBtnDialog2(){
        ProgressDialog progressDialog = init();
        //设置进度条的第二进度（浅色部分）
        progressDialog.setSecondaryProgress(50);
        progressDialog.show();
        progressDialog.setProgress(10);
        //设置进度条的图片，Drawable类型;
        // progressDialog.setProgressDrawable(getResources().getDrawable(R.mipmap.ic_launcher));
    }

    public void onclick(View view) {
        switch (view.getId()){
            case R.id.btn1:
                setBtnDialog();
                break;
            case R.id.btn2:
                setBtnDialog2();
                break;
            case R.id.btn3:
                setBtnDialog3();
                break;
            default:
                break;
        }
    }


    private ProgressDialog init(){
        ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("消息来了");
        progressDialog.setIcon(R.mipmap.ic_launcher);
        progressDialog.setMessage("接到了");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMax(100);
        return progressDialog;
    }
}
